package com.stream.service.impl;

import com.google.common.collect.Maps;
import com.stream.repository.SysRoleMenuRepository;
import com.stream.service.SysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created by yebaokang on 2017/5/23.
 */
@Service("sysRoleMenuService")
public class SysRoleMenuServiceImpl implements SysRoleMenuService{

    @SuppressWarnings("all")
    @Autowired
    private SysRoleMenuRepository sysRoleMenuRepository;

    @Override
    public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
        //先删除角色与菜单的关系
        sysRoleMenuRepository.delete(roleId);

        if (menuIdList.size() == 0) {
            return;
        }

        //保存角色与菜单的关系
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("roleId", roleId);
        map.put("menuIdList", menuIdList);
        sysRoleMenuRepository.save(map);
    }

    @Override
    public List<Long> queryMenuIdList(Long roleId) {
        return sysRoleMenuRepository.queryMenuIdList(roleId);
    }
}
